package com.cloudsigns.factorymanager2.project.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;

/**
 * 添加竣工评价
 * Created by tony on 2017/12/20.
 */

public class AddCompletionOfEvaluationActivity extends Activity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {
    private View rl_back;
    private TextView tv_title;
    private RadioGroup rg_construction_quality, rg_onstruction_schedule, rg_construction_environment, rg_construction_safe, rg_final_evaluation;
    private Button btn_upload;
    private String quality, schedule, environment, safe, final_evaluation;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.layout_add_completion_of_evaluation);

        init();
    }

    private void init() {
        rl_back = findViewById(R.id.rl_back);
        tv_title = findViewById(R.id.tv_title);
        rg_construction_quality = findViewById(R.id.rg_construction_quality);
        rg_onstruction_schedule = findViewById(R.id.rg_onstruction_schedule);
        rg_construction_environment = findViewById(R.id.rg_construction_environment);
        rg_construction_safe = findViewById(R.id.rg_construction_safe);
        rg_final_evaluation = findViewById(R.id.rg_final_evaluation);
        btn_upload = findViewById(R.id.btn_upload);


        rg_construction_quality.setOnCheckedChangeListener(this);
        rg_onstruction_schedule.setOnCheckedChangeListener(this);
        rg_construction_environment.setOnCheckedChangeListener(this);
        rg_construction_safe.setOnCheckedChangeListener(this);
        rg_final_evaluation.setOnCheckedChangeListener(this);
        tv_title.setText(getResources().getText(R.string.completion_of_evaluation));
        rl_back.setOnClickListener(this);
        btn_upload.setOnClickListener(this);
    }

    private void upload() {
        Intent mIntent = new Intent();
        Bundle mBundle = new Bundle();
        mBundle.putString("quality", quality);
        mBundle.putString("schedule", schedule);
        mBundle.putString("environment", environment);
        mBundle.putString("safe", safe);
        mBundle.putString("final_evaluation", final_evaluation);
        mIntent.putExtras(mBundle);
        setResult(ConstantUtil.START_ACTIVITY_KEY_1, mIntent);

        finish();

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rl_back:
                finish();
                break;
            case R.id.btn_upload:
                upload();
                break;

        }
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, @IdRes int id) {
        if (radioGroup == rg_construction_quality) {
            if (id == R.id.rb_construction_quality_ok) {
                quality = "好";
            } else if (id == R.id.rb_construction_quality_general) {
                quality = "一般";
            } else if (id == R.id.rb_construction_quality_difference) {
                quality = "差";
            }

        } else if (radioGroup == rg_onstruction_schedule) {
            if (id == R.id.rb_onstruction_schedule_ok) {
                schedule = "好";
            } else if (id == R.id.rb_onstruction_schedule_general) {
                schedule = "一般";
            } else if (id == R.id.rb_onstruction_schedule_difference) {
                schedule = "差";
            }

        } else if (radioGroup == rg_construction_environment) {
            if (id == R.id.rb_construction_environment_ok) {
                environment = "整洁";
            } else if (id == R.id.rb_construction_environment_general) {
                environment = "一般";
            } else if (id == R.id.rb_construction_environmentdifference) {
                environment = "脏乱";
            }

        } else if (radioGroup == rg_construction_safe) {
            if (id == R.id.rb_construction_safe_ok) {
                safe = "好";
            } else if (id == R.id.rb_construction_safe_general) {
                safe = "一般";
            } else if (id == R.id.rbconstruction_safe_difference) {
                safe = "差";
            }

        } else if (radioGroup == rg_final_evaluation) {
            if (id==R.id.rb_final_evaluation_excellent){
                final_evaluation = "优";
            } else if (id == R.id.rb_final_evaluation_ok) {
                final_evaluation = "合格";
            } else if (id == R.id.rb_final_evaluation_general) {
                final_evaluation = "不合格";
            }
        }
    }
}
